%% main code for Markov policy

clear all;
clc;
close all;
warning off;

T1_frac = 0.5; % T1_frac*log(T1),starting point for T1 during the transition, fraction of Tss1



n     =  2; % number of countries
ns      =  1;
beta   = 1/(1+0.1);     % discount factor
theta  = 2;
sigma = 1.0001;
gL      = 0.02;
dbar   = 1.1;
delta = 1-1/(1+gL);

rhoa   = 0.95;
std_ea = 0.1;

rhod   = 0.95;
std_ed = 0.1;

L = ones(n,1);
betas = ones(ns,1)/ns;

rho   = beta*(1-delta);
rbest = delta/(theta*(1-beta*(1-delta))+delta);

ncountries=n;
nsectors = ns;

alpha = [1;0.9];

gcoef0 = zeros(n-1,ns,n,ns);

load sgcoef0
% gcoef1 = zeros(n-1,ns);
% gcoef2 = zeros(n-1,ns);

mpara(1) = n;
mpara(2) = ns;
mpara(3) = beta;
mpara(4) = theta;
mpara(5) = sigma;
mpara(6) = gL;
mpara(7) = dbar;
mpara(8) = delta;
mpara(9) = rho;

inn = 9;
for i=1:n
    inn = inn+1;
    mpara(inn) = L(i);
end

for i=1:n
    for j=1:ns
        inn = inn+1;
        mpara(inn) = alpha(i,j);
    end
end

for j=1:ns
    inn = inn+1;
    mpara(inn) = betas(j);
end

inn = inn+1;
mpara(inn) = rhoa;

inn = inn+1;
mpara(inn) = std_ea;

inn = inn+1;
mpara(inn) = rhod;

inn = inn+1;
mpara(inn) = std_ed;

for i=1:n-1
    for j=1:ns
        for ii=1:n
            for jj=1:ns
                inn = inn+1;
                mpara(inn) = gcoef0(i,j,ii,jj);
            end
        end
    end
end

main_notForDynare_solveSS;


inn = inn+1;
mpara(inn) = T1_frac*log(Tss(1));

inn = inn+1;
mpara(inn) = log(Tss(2));


save setpara_perfect mpara

dynare markov2_perfect;

